package com.rongma.waterdrop.network.api;

import android.content.Context;

import com.rongma.waterdrop.listener.getBmob.GetTaskListener;
import com.rongma.waterdrop.model.Task;
import com.rongma.waterdrop.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.FindListener;

/**
 * Created by RongMa on 16/6/11.
 */

public class GetTaskAPI 
{
    private GetTaskListener listener;

    public GetTaskAPI(GetTaskListener listener)
    {
        this.listener = listener;
    }

    //从网络获取所有的Task数据
    public void getDataFromBmob(final Context context)
    {
        new Thread(new Runnable() {
            @Override
            public void run() {
                BmobQuery<Task> taskBmobQuery = new BmobQuery<Task>();
                taskBmobQuery.findObjects(context, new FindListener<Task>() {
                    @Override
                    public void onSuccess(List<Task> list) {
                        listener.onSuccess((ArrayList<Task>) list);
                    }

                    @Override
                    public void onError(int i, String s){
                        listener.onError(s);
                    }
                });

            }
        }).start();
    }


}
